import Toast from "../../../dist/toast/toast";
var util = require('../../../utils/util.js');
var app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        collectList: {},
    },
    /**
     * 生命周期函数--监听页面加载(每页显示10条记录)
     */
    onLoad: function (options) {
        wx.showLoading({
            title: '加载中'
        });
        this.getMycollectList()

    },
    /**
     * 跳转博客详情页
     * @param event
     */
    onDetail: function (event) {
        var id = event.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/pages/post-detail/post-detail?id=" + id + "&title=我的收藏"
        })
    },
    /**
     * 获取收藏列表
     */
    getMycollectList() {
        var dataUrl = app.globalData.apiBase +
            "/blog/listCollect?userId=" + app.globalData.userId + "&pageNum=0&pageSize=10";
        util.ajax(dataUrl, "get", null, this.processData);
    },

    processData: function (data) {
        if(data!=null){
            var indeList=data.list
            indeList.forEach((item)=>{
                item.createTime=util.date_time(item.createTime);
            })
        }
        this.setData({
            collectList: data.list,
        });
        wx.hideNavigationBarLoading();
        wx.stopPullDownRefresh();
        wx.hideLoading();
    },

    /**
     * 取消收藏
     * @param event
     */
    onLike: function (event) {
        var articleId = event.currentTarget.dataset.id;
        var dataUrl = app.globalData.apiBase +
            "/blog/addCollect?articleId=" + articleId + "&flag=1";
        util.ajax(dataUrl, "get", null, (dataRespResult) => {
            this.getMycollectList()
            Toast(dataRespResult);
        })
    },
})
